<!-- 我的症状页面 -->

<template>
	<view class="container">
		<lk-topbar :title="'我的主诉'" :backcolor="'#fff'" @back="back"></lk-topbar>
		<view class="p30">
			<!-- 引入记录组件 -->
			<lk-record-sym :types="'pres'"  @delectTap="delectTap" :lists='symptom'></lk-record-sym>
		</view>
		<view class="btn w75 h84 mauto radius50" @click="save()"> 保存</view>
		
	</view>
</template>

<script>
	import lkRecordSym from '../../components/lk-record-sym/index.vue'
	export default {
		name:"",
		data() {
			return {
				symptom:[],//我的症状
				isSave:true,
			}
		},
		props:{
			
		},
		components:{
			lkRecordSym
		},
		onLoad() {
			this.getUserDetail();
		},
		onShow() {
			 
			let pages =getCurrentPages();
			let cur = pages[pages.length -1];
			// 判断是否是修改页面返回
			if(typeof cur.data.med != 'undefined'){
				this.isSave = false;
				if(cur.data.cindex != -1){
					this.symptom.splice(cur.data.cindex,1,cur.data.med);
				}else{
					this.symptom.push(cur.data.med)
				}
				delete(cur.data.med)
			}
			
		},
		methods: {
			// 保存
			save(){
				let _this = this;
				 _this.$utils.request({
					 url:"/patient/user_info/",
					 method:"PUT",
					 data:{
						 symptom:this.symptom,
					 }
				 }).then(res=>{
					 wx.showToast({
						 title:"保存成功！"
					 })
					 this.isSave =true;
					 setTimeout(()=>{
						this.$routeJump.back()
					 },2000)
				 })
			},
			//请求用户信息
			getUserDetail(){
				let _this = this;
				 _this.$utils.request({
					 url:"/patient/user_info/",
				 }).then(res=>{
					 console.log(res.data.symptom)
					 _this.symptom = res.data.symptom;
				 })
			},
			/**
			 * 删除某条数据
			 * @param {Object} o 返回数据
			 */
			delectTap(o){
				this.isSave  =false;
				this.symptom.splice(o.ind,1);
			},
			
			// 页面返回
			back(){
				let _this =this;
				if(_this.isSave){
					_this.$routeJump.back()
				}else{
					wx.showModal({
						title:"提示",
						content:"你还没保存，是否保存？",
						success(res){
							if(res.confirm){
								_this.save()
							}else{
								_this.$routeJump.back()
							}
						}
					})
				}
			},
		}
	}
	
</script>

<style lang="scss" scoped>
	.container{
		background-color: #fff;
		.btn{
			background-color: #ffb526;
		}
	}

</style>
